<?php
/**
 * Array related utility functions tests.
 *
 * @author Sergey Kuznetsov <clk824@gmail.com>
 */

require "array.php";

class ArrayTest extends PHPUnit_Framework_TestCase
{
	protected $array;

	protected function setUp()
	{
		$this->array = ["foo" => 1, "bar" => [ "baz" => 2 ] ];
	}

	public function testEmpty()
	{
		clk824\array_put($this->array, 'foo');
		clk824\array_put($this->array, 'bar');
		clk824\array_put($this->array, 'baz');
		$this->assertTrue(empty($this->array));
			
	}

	public function testPut()
	{
		clk824\array_put($this->array, 'baz', 3);
		$this->assertEquals(3 , count($this->array));
		$this->assertFalse(empty($this->array));
	}

	public function testGet()
	{
		$this->assertEquals(1 , clk824\array_get($this->array, "foo"));
		$this->assertEquals(2 , clk824\array_get($this->array, "bar/baz"));
			
		// try to get non-existent element
		$this->setExpectedException('Exception');
		clk824\array_get($this->array, "baz");
	}
}